package com.pan.basecommon.model.http.helper;

import com.pan.basecommon.model.http.api.ApiService;
import com.pan.basecommon.model.http.api.NetConfig;
import com.pan.basecommon.model.http.api.Signature;
import com.pan.basecommon.model.http.entity.BaseResponse;
import com.pan.basecommon.model.http.utils.NetworkUtils;

import java.util.HashMap;

import javax.inject.Inject;

import io.reactivex.Observable;

public class IHttpHelperImpl implements IHttpHelper {

    public NetworkUtils mNetworkUtils;

    private ApiService getHttpApiServiceGson(String host) {
        return mNetworkUtils.getHttpApiService(ApiService.class, host, true);
    }

    private ApiService getHttpApiServiceNotGson(String host) {
        return mNetworkUtils.getHttpApiService(ApiService.class, host, false);
    }

    private ApiService getHttpsApiServiceGson(String host) {
        return mNetworkUtils.getHttpsApiService(ApiService.class, host, true);
    }

    private ApiService getHttpsApiServiceNotGson(String host) {
        return mNetworkUtils.getHttpsApiService(ApiService.class, host, false);
    }

    @Inject
    public IHttpHelperImpl(NetworkUtils networkUtils) {
        this.mNetworkUtils = networkUtils;
    }

    @Override
    public Observable<BaseResponse> createMemberCard(String host, String memberCardId) {
        long timeStamp = System.currentTimeMillis();
        HashMap<String, Object> signMap = new HashMap<>();
        signMap.put("memberCardId", memberCardId);
        signMap.put("timestamp", timeStamp);
        String sign = NetworkUtils.getSign(signMap, Signature.DEFAULT_KEY);
        return getHttpApiServiceGson(host).createMemberCard(NetConfig.Action.CREATE_MEMBER_CARD, memberCardId, timeStamp, sign);
    }
}
